package com.itserver.controller.sysController;


import com.itserver.pojo.PageResult;
import com.itserver.pojo.Result;
import com.itserver.pojo.sys.Dept;
import com.itserver.service.sys.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sys/dept")
//部门管理
public class DeptController  {

    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result list( Dept queryDept){
        log.info("查询部门列表");
        PageResult<Dept> pageResult = deptService.findAll(queryDept);
        return Result.success( pageResult );
    }
    // 删除接口
    @DeleteMapping
    public Result delete( @RequestParam List<Integer> ids ){
        log.info("批量删除部门 ids<UNK>{}", ids);
        deptService.deleteById(ids);
        return Result.success();
    }

    // 新增部门
    @PostMapping
    public Result add(@RequestBody Dept dept ){
        deptService.add(dept);
        return Result.success();
    }

    // 修改部门
    @PutMapping
    public Result update(@RequestBody Dept dept ){
        log.info("修改部门 depts {}", dept);
        deptService.update(dept);
        return Result.success();
    }
    // 根据id查询详情
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据id查询id {}", id);
        Dept dept = deptService.getById(id);
        return Result.success(dept);
    }
}
